package src.epat.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import src.epat.model.TaskModel;
import src.epat.service.TaskService;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/task")
public class TaskController {


    @Autowired
    TaskService taskService;

    @RequestMapping(value = "/add")
    public void add(@RequestBody TaskModel taskModel) {
        taskService.addTask(taskModel);
    }



    @RequestMapping(value = "/update")
    public void update(@RequestBody TaskModel taskModel) {
        taskService.updateTask(taskModel);
    }


    @RequestMapping(value = "/finishTask")
    public void update(Long taskId, Boolean flag) {
        taskService.finishTask(taskId, flag);
    }



    @RequestMapping(value = "/finishTaskList")
    public void update(@RequestBody List<Long> taskIdList, Boolean flag) {
        taskService.finishTaskList(taskIdList, flag);
    }


    @RequestMapping(value = "/delList")
    public void delList(@RequestBody List<Long> taskIdList) {
        taskService.delList(taskIdList);
    }

    @RequestMapping(value = "/listToDo")
    public List<TaskModel> listToDo(Integer endIndex, @RequestParam(required = false) String searchName) {
        return taskService.listToDo(endIndex, searchName, true);
    }


    @RequestMapping(value = "/listFinish")
    public List<TaskModel> listFinish(Integer endIndex,@RequestParam(required = false) String searchName, @RequestParam(required = false) Boolean flag) {
        return taskService.listFinish(endIndex, searchName);
    }


    @RequestMapping(value = "/listAbort")
    public List<TaskModel> listAbort(Integer endIndex,@RequestParam(required = false) String searchName) {
        return taskService.listToDo(endIndex, searchName, false);
    }



    @RequestMapping(value = "/listDel")
    public List<TaskModel> listDel(Integer endIndex,@RequestParam(required = false) String searchName) {
        return taskService.listDel(endIndex, searchName);
    }

}
